﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="course-list.aspx.cs" Inherits="VQWEB.administrator.english.courses.course_list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr class="active">
                    <th>
                        #
                    </th>
                    <th>
                        <input name="chkAll" type="checkbox" value=" " />
                    </th>
                    <th>
                        Ma khoa hoc
                    </th>
                    <th>
                        Ten khoa hoc
                    </th>
                    <th>
                        Number Level
                    </th>
                    <th>
                       Test
                    </th>
                     
                    <th>
                        Active
                    </th>
                </tr>
            </thead>
            <tbody>
               
            </tbody>
        </table>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
<script type="text/javascript">
    ShowToolBar("add");
    var url_ashx = "/admin/english/course/handler";
    $("#btnAdd").live("click", function () {
        window.location = "/admin/english/course/add";
    });
    $("#btnEdit").live("click", function () {
        var Id = "";
        Id = $("input[name='chkItem']:checked").first().attr("value");
        if (Id != undefined)
            window.location = "/admin/english/course/edit/" + Id;
    });
    $("#btnLockUnlock").live("click", function () {
        var array = new Array();
        $("input[name='chkItem']:checked").each(function (i) {
            array[i] = this.value;
        });
        if (array.length > 0) {
            $.post(url_ashx, { lockunlock_course: JSON.stringify(array) }, function (data) {
                var plusData = $.parseJSON(data);
                $("tbody").empty();
                ShowCourseHtml(plusData);
            });
        }
    });
    //Delete
    $("#btnDelete").live("click", function () {
        var array = new Array();
        $("input[name='chkItem']:checked").each(function (i) {
            array[i] = this.value;
        });
        if (array.length > 0) {
            if (confirm("Bạn muốn xóa bản ghi không ???")) {
                $.post(url_ashx, { delete_course: JSON.stringify(array) }, function (data) {
                    var plusData = $.parseJSON(data);
                    $("tbody").empty();
                    ShowCourseHtml(plusData);
                });
            }
        }

    });
    //list 
    $(document).ready(function () {  
        $.post(url_ashx, { list_course: "list_course" }, function (data) {
            var plusData = $.parseJSON(data);
            ShowCourseHtml(plusData);
        });
    });

    //function show
    function ShowCourseHtml(table) {
        var html = "";
        $.each(table, function (i, obj) {
            html += "<tr>";
            html += "<td>";
            html += i + 1;
            html += "</td>";
            html += "<td>";
            html += "<input name=\"chkItem\" type=\"checkbox\" value=" + obj.course_id + " />";
            html += "</td>";
            html += "<td>";
            html += obj.course_code;
            html += "</td>";
            html += "<td>";
            html += obj.course_title;
            html += "</td>";
            html += "<td>";
            html += obj.level;
            html += "</td>";
            html += "<td>";
            html += obj.test;
            html += "</td>";           
            html += "<td>";
            html += (obj.course_active == true) ? "kich hoat" : "chua kich hoat";
            html += "</td>";
            html += "</tr>";
        });
        $("tbody").append(html);
    }

</script>
</asp:Content>
